<!DOCTYPE html>
<!--suppress ALL -->
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head th:include="include/head::commonHeaderCustomEdit((${knowledgeId>0?'修改知识点':'添加知识点'}),~{::style})">
    <style type="text/css">
        .error {
            color: red !important;
            border-color: red !important;
        }

        .error:focus {
            color: red !important;
            border-color: red !important;
        }

        .red {
            color: red !important;
        }

        .dataArea .title {
            padding: 5px 10px 0 0;
        }

        .dataArea .item {
            padding: 0 20px 10px 0;
        }

        .action {
            text-align: center;
            margin-left: 10px !important;
        }

        .action button {
            width: 100%;
        }

        .sp_container {
            width: 100% !important;
        }

        .sp_input {
            padding-left: 8px !important;
        }

        .tbList {
            margin: 5px 0;
            padding: 0;
        }

        .error-border {
            border: solid red 1px !important;
        }

        .form-group {
            margin-bottom: 0;
        }

        .clear {
            clear: both;
        }

        .textbookArea {
            margin-right: 8%;
            margin-left: 10%;
            padding: 20px;
            background: #f3f4f5;
            margin-bottom: 10px;
        }

        body {
            overflow-x: hidden;
        }

        .btn-add-textbook {
            margin-left: 10px;
            width: 100%;
            border: none;
        }

        .btn-add-textbook:hover {
            border: none;
        }

        .sp_result_area {
            width: 400px !important;
        }
    </style>
</head>
<body>
<link rel="stylesheet" type="text/css" th:href="@{/static/lib/selectpage/selectpage.css}"/>
<div class="ch-container">
    <div class="row">
        <form class="form-horizontal" method="post" onsubmit="return false;">
            <div class="box">
                <legend class="text-center" style="padding-bottom:15px;font-weight: bold;" contenteditable="false" th:text="${knowledgeId>0?'修改知识点':'添加知识点'}">知识点</legend>
                <div class="dataArea">
                    <ul>
                        <li>
                            <div class="form-group">
                                <div class="col-xs-2 text-right title"><i class="red">*</i>知识点名称</div>
                                <div class="col-xs-9 item">
                                    <input class="form-control" id="cnName" name="cnName" type="text" placeholder="请输入知识点名称" required/>
                                    <p class="message error hide">错误信息</p>
                                </div>
                            </div>
                        </li>
                        <li class="textbookArea">
                            <span style="cursor:pointer;padding: 10px 0;">教材与页码</span>
                            <a onclick="hidestate($(this))" class="itemhide" hidestate="0" style="float:right;cursor:pointer;">收缩</a>
                            <div id="textbookList" class="textbookList">
                                <div id="textbookItem1" class="textbookItem">
                                    <i onclick="deletetbitem($(this))" style="cursor:pointer;padding: 10px 0;" class="glyphicon glyphicon-remove"></i>
                                    <div class="form-group">
                                        <div class="col-md-1 col-xs-2 text-right title"><i class="red">*</i>选择教材</div>
                                        <div class="col-md-10 col-xs-9 item">
                                            <input class="form-control" type="text" placeholder="请选择关联教材" id="relatedTextbooks1" name="relatedTextbooks1">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-md-1 col-xs-2 text-right title"><i class="red">*</i>选择页码</div>
                                        <div class="col-md-10 col-xs-9 item">
                                            <input class="form-control" id="page1" name="page1" type="text" placeholder="请选择教材页码，可多选"/>
                                            <p class="message error hide">错误信息</p>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-md-1 col-xs-2 text-right title"><i class="red">*</i>选择考点</div>
                                        <div class="col-md-10 col-xs-9 item">
                                            <div class="col-sm-3" style="padding: 0;padding-right: 20px;">
                                                <select class="form-control" id="mistakeId1" onchange="getKPChild($(this).attr('id'));" required>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <span class="col-md-2 col-xs-3 text-left ">
                                    <button id="btn-add-textbook" class="btn btn-info btn-add-textbook"><span>添加教材和页码</span></button>
                                </span>
                            </div>
                        </li>
                        <li>
                            <div class="form-group action">
                                <span class="col-md-1 col-xs-1 text-right"></span>
                                <span class="col-md-2 col-xs-2 text-centert">
                                    <button class="btn btn-default" onclick="cancel();"><span>取消</span></button>
                                </span>
                                <span class="col-md-2 col-xs-2 text-center">
                                    <button id="submit-button" data-loading-text="保存中..." class="btn btn-primary" onclick="save(0);"><span>提交</span></button>
                                </span>
                            </div>
                        </li>
                    </ul>
                </div>
            </div>
        </form>
    </div>

    <!-- template -->
    <div id="textbookItemTemplate" class="hide">
        <div id="textbookItem" class="textbookItem">
            <i onclick="deletetbitem($(this))" style="cursor:pointer;padding: 10px 0;" class="glyphicon glyphicon-remove"></i>
            <div class="form-group">
                <div class="col-md-1 col-xs-2 text-right title"><i class="red">*</i>选择教材</div>
                <div class="col-md-10 col-xs-9 item">
                    <input class="form-control relatedTextbooks" type="text" placeholder="请选择关联教材" id="relatedTextbooks" name="relatedTextbooks">
                </div>
            </div>
            <div class="form-group">
                <div class="col-md-1 col-xs-2 text-right title"><i class="red">*</i>选择页码</div>
                <div class="col-md-10 col-xs-9 item">
                    <input class="form-control page" id="page" name="page" type="text" placeholder="请选择教材页码，可多选"/>
                    <p class="message error hide">错误信息</p>
                </div>
            </div>
            <div class="form-group">
                <div class="col-md-1 col-xs-2 text-right title"><i class="red">*</i>选择考点</div>
                <div class="col-md-10 col-xs-9 item">
                    <div class="col-sm-3" style="padding: 0;padding-right: 20px;">
                        <select class="form-control mistakeId" id="mistakeId" name="mistakeId" onchange="getKPChild($(this).attr('id'));" required>
                        </select>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div th:include="include/onload_js::onloadJSCustomEdit(~{::script})">
        <script type="text/javascript" th:src="@{'/static/lib/selectpage/selectpage.js?v=201901250005'}"></script>
        <script th:inline="javascript">
            /*<![CDATA[*/
            var knowledgeId = /*[[${knowledgeId}]]*/0;
            var relateTextbookArray = [];
            var isFromQuestion = /*[[${isFromQuestion}]]*/0;
            /*]]>*/

            //选中的id集合
            var selectedIds = null;

            var ADD = "add";
            var EDIT = "edit";
            var actionType = knowledgeId > 0 ? EDIT : ADD;

            var currentTextbookIndex = 1;

            $(function () {
                // 添加教材和页码
                $("#btn-add-textbook").on("click", function (e) {
                    e.preventDefault();

                    // 组件ID增加
                    // console.log("currentTextbookIndex before:" + currentTextbookIndex);
                    currentTextbookIndex = currentTextbookIndex + 1;
                    // console.log("currentTextbookIndex after:" + currentTextbookIndex);

                    // 设置模板ID
                    var template = $("#textbookItemTemplate").find(".textbookItem").eq(0).clone();
                    $(template).attr("id", "textbookItem" + currentTextbookIndex);

                    // console.log("template before:" + $(template).html());

                    var tb = $(template).find(".relatedTextbooks").eq(0);
                    $(tb).attr("id", "relatedTextbooks" + currentTextbookIndex);
                    $(tb).attr("name", "relatedTextbooks" + currentTextbookIndex);

                    var pg = $(template).find(".page").eq(0);
                    $(pg).attr("id", "page" + currentTextbookIndex);
                    $(pg).attr("name", "page" + currentTextbookIndex);

                    var kp = $(template).find(".mistakeId").eq(0);
                    $(kp).attr("id", "mistakeId" + currentTextbookIndex)
                    $(kp).attr("name", "mistakeId" + currentTextbookIndex)

                    //  console.log("template after:" + $(template).html());

                    $("#textbookList").append(template);

                    // 初始化
                    initAdd(currentTextbookIndex);
                });

                // 数据初始化
                initPage();

                //表单验证
                $('form').validate({
                    focusInvalid: true,
                    errorPlacement: function (error, element) {
                        var errorMsg = error[0].innerHTML;
                        var elem = element[0];
                        $(elem).next('.message').removeClass("hide").addClass("error").html(errorMsg).show();
                    },
                    success: function (element) {
                        var elem = $(element)[0].htmlFor;
                        $(elem).next('.message').hide();
                    }
                });
            });

            /**
             * 获取知识点详情
             */
            function initPage() {
                console.log("init page");
                if (actionType == ADD) {
                    initAdd(1);
                } else {
                    // 开启加载层
                    layer.load(2, {
                        shade: [0.6, '#fff'], content: '数据加载中...', success: function (layero) {
                            layero.find('.layui-layer-content').css({
                                'padding-top': '6px',
                                'width': '150px',
                                'padding-left': '40px'
                            });
                            layero.find('.layui-layer-ico16, .layui-layer-loading .layui-layer-loading2').css({
                                'width': '150px !important',
                                'background-position': '2px 0 !important'
                            });
                        }
                    });
                    initEdit();
                }
            }

            function initAdd(index) {
                console.log("init Add,index:" + index);
                //关联教材
                $('#relatedTextbooks' + index).selectPage({
                    showField: 'name',
                    keyField: 'id',
                    data: '/questionKnowledge/showTextbooks',
                    multiple: false,//单选
                    pageSize: 5,
                    eAjaxSuccess: function (data) {
                        // console.log("data:" + JSON.stringify(data));
                        return data;
                    },
                    eSelect: function (data) {
                        changeMaterial(data.address, index, "");
                    }
                });

                // 录入校验
                $("#relatedTextbooks" + index + "_text").on('blur', function () {
                    var relatedTextbooksObj = $("#relatedTextbooks" + index);
                    if (relatedTextbooksObj.val() === '') {
                        relatedTextbooksObj.parent().addClass("error");
                        relatedTextbooksObj.parent().addClass("error-border");
                    } else {
                        relatedTextbooksObj.parent().removeClass("error");
                        relatedTextbooksObj.parent().removeClass("error-border");
                    }
                });

                // 教材页码
                $('#page' + index).selectPage({
                    showField: 'name',
                    keyField: 'id',
                    data: {},
                    multiple: true,//打开多选
                    maxSelectLimit: 0,//无限制页码
                    pageSize: 5,
                    // eAjaxSuccess: function (data) {
                    //     return data;
                    // },
                    eSelect: function (data) {
                        // console.log("page_text:" + $('#page' + index).selectPageText());
                    }
                });

                $("#page" + index + "_text").on('blur', function () {
                    var pageObj = $("#page" + index);
                    if (pageObj.val() === '') {
                        pageObj.parent().addClass("error");
                    } else {
                        pageObj.parent().removeClass("error");
                    }
                });

                // 考点初始化
                getKPChild("mistakeId" + index, index);
            }

            function initEdit() {
                $.ajax({
                    type: 'post',
                    url: '/questionKnowledge/detail',
                    data: {knowledgeId: knowledgeId},
                    cache: false,
                    // contentType: "application/json;charset=utf-8",
                    // dataType: 'json',
                    success: function (res) {
                        if (res.status > 0) {
                            console.log("questionKnowledge detail data is=>", res.data);
                            var know = res.data;
                            $("#cnName").val(know.cnName);

                            // 教材初始化
                            relateTextbookArray = (know.relateTextbookString == null || know.relateTextbookString == "") ? [] : know.relateTextbookString.split(",");

                            console.log("relateTextbookArray=>", relateTextbookArray)

                            // ==设置第一个
                            // 初始化控件
                            initAdd(1);

                            if (relateTextbookArray.length > 0) {
                                // 地址
                                var addressArray = (know.address == null || know.address == "") ? [] : know.address.split(",");
                                // 页码
                                var pagesArray = (know.relatePageString == null || know.relatePageString == "") ? [] : know.relatePageString.split("|,");
                                // 考点
                                var mistakesIdArray = [];
                                var tempArray = know.relateMistakesIdString.split("|,")
                                tempArray.forEach(function (v) {
                                    var val = v.split(",")[0];
                                    // console.error("val=>", val)
                                    mistakesIdArray.push(val);
                                });

                                console.log("addressArray=>", addressArray);
                                console.log("pagesArray=>", pagesArray);
                                console.log("mistakesIdArray=>", mistakesIdArray);

                                // ==设置剩下的
                                for (var idx in relateTextbookArray) {
                                    if (idx > 0) {//跳过第一个
                                        // 初始化控件
                                        $("#btn-add-textbook").click();
                                    }

                                    // 设置教材
                                    var otherTextbookObj = $("#relatedTextbooks" + currentTextbookIndex);
                                    otherTextbookObj.val(relateTextbookArray[idx]);
                                    otherTextbookObj.selectPageRefresh();
                                    // 设置页码
                                    changeMaterial(addressArray[idx], currentTextbookIndex, pagesArray[idx]);

                                    // 设置考点
                                    initKPChild(mistakesIdArray[idx], idx);
                                }
                            } else {
                                //关闭加载层
                                layer.closeAll('loading');
                            }
                        } else {
                            layer.msg(res.msg, {icon: 2});
                        }
                    }
                });
            }

            function contains(arr, obj) {
                var i = arr.length;
                while (i--) {
                    if (arr[i] === obj) {
                        return true;
                    }
                }
                return false;
            }

            /**
             * 初始化考点
             * idx 当前考点索引
             */
            function initKPChild(currentlastMistakesId, idx) {
                console.log("currentlastMistakesId=>", currentlastMistakesId);

                $.ajax({
                    type: 'post',
                    url: "/question/mistakes/parent/" + currentlastMistakesId,
                    data: {},
                    dataType: 'json',
                    async: false,
                    success: function (resp) {
                        console.log("question.mistakes.parent.result:" + JSON.stringify(resp));
                        if (resp != null && resp.status == 1) {
                            selectedIds = resp.data;
                            console.log("selectedIds:", resp.data);
                            if (selectedIds.length > 0) {
                                var firstMistakeId = selectedIds[selectedIds.length - 1];
                                selectedIds.pop();
                                // console.error("firstMistakeId:", firstMistakeId);
                                var mistakeId = "mistakeId" + (parseInt(idx) + 1);
                                // console.error("resp mistakeId:", mistakeId);
                                $("#" + mistakeId).val(firstMistakeId);

                                // 初始化完毕，选中
                                var hidId = "hid" + mistakeId;
                                console.log("hidId=>", hidId)
                                console.log("firstMistakeId=>", firstMistakeId)
                                $("#" + hidId).val(firstMistakeId);

                                getKPChild(mistakeId);
                            }
                        } else {
                            layer.msg('考点分类数据尚未初始化', {icon: 2});
                        }
                    }
                })
            }

            /**
             * 考点多级联动
             * id 当前考点控件ID
             */
            var getKPChild = function (id) {
                //var elem= $("#" + id);
                var kpv = $("#" + id).val();
                // 默认第一级分类父级设置为0
                kpv = isEmpty(kpv) ? 0 : kpv;
                console.log("当前考点控件ID=>" + id + ",当前考点ID=>" + kpv);

                // 确保子类名称只包含一个child（替换全部不分大小写）
                var nochild = id.replace(/child/gi, "");
                console.log("nochild=>", nochild)

                var container = $("#" + id).parents(".item").get(0);
                var currentItem = $($("#" + id)).parent();
                var next = $(currentItem).next();

                $.ajax({
                    type: 'post',
                    url: "/question/mistakes/" + kpv,
                    data: {},
                    dataType: 'json',
                    async: false,
                    success: function (res) {
                        if (res.data != null && res.data.length > 0) {
                            // 获取option
                            var template = initOption(res);

                            // 获取第一级考点数据
                            if (kpv == 0) {
                                // 如果有了，防止重复初始化
                                var oplen = $("#" + id + "  option").length;
                                if (oplen > 0) {
                                    console.log("考点已经初始化过");
                                    return;
                                }

                                // 初始化第一级
                                $("#" + id).append(template);
                                console.log("初始化第一级考点数据")
                                // 初始化隐藏域
                                var elemName = nochild;
                                $(container).parent().append("<input type=\"hidden\" id=\"hid" + elemName + "\">")
                                console.log("elemName=>", elemName);
                            } else {
                                if (typeof next.get(0) == "undefined") {
                                    console.log("初始化新的select");
                                    // 创建子级，并获取数据
                                    var elemId = "child" + id;
                                    console.log("elemId=>", elemId);
                                    var elem = '<div class="col-sm-3" style="padding: 0;padding-right: 20px;">' +
                                        '<select class="form-control" id="' + elemId + '" name="' + elemId + '" onchange="getKPChild($(this).attr(\'id\'));" required>' +
                                        template +
                                        '</select>' +
                                        '</div>';
                                    $(container).append(elem);
                                    // console.log("elem=>", elem);

                                    //修改选中
                                    if (actionType == EDIT) {
                                        //触发change方法
                                        console.log("修改触发change方法")
                                        if (selectedIds.length > 0) {
                                            var nextVal = selectedIds[selectedIds.length - 1];
                                            selectedIds.pop();
                                            console.log("nextSelect.val=" + nextVal);
                                            var nextSelect = "#" + elemId;
                                            $(nextSelect).val(nextVal);

                                            // 初始化完毕，选中
                                            var hidId = "hid" + nochild;
                                            console.log("hidId=>", hidId)
                                            $("#" + hidId).val(nextVal);

                                            // 获取子级
                                            getKPChild(elemId);
                                        }
                                    }
                                } else {
                                    console.log("无需初始化");//需要更新
                                    $(next).find("select").html(template);
                                }
                            }
                        } else {
                            //没数据的话要移除子控件
                            if (typeof next.get(0) != "undefined") {
                                $(next).remove();
                            }
                            var hidId = "hid" + nochild;
                            console.log("hidId=>", hidId)
                            $("#" + hidId).val(kpv);
                            console.log("没有了");
                        }
                    }
                });
            }

            /**
             * 初始化考点下拉控件的option
             */
            function initOption(res) {
                var templateOptions = '<option value="">-考点-</option>\n';

                for (var cIdx in res.data) {
                    var cItem = res.data[cIdx];
                    option = '<option value="' + cItem.id + '">' + cItem.cnName + '</option>\n';
                    templateOptions = templateOptions + option;
                }
                return templateOptions;
            }

            function isEmpty(s) {
                return s == null || s == "";
            }

            function changeMaterial(address, index, currentPages) {
                if (address != null && address !== "") {
                    console.log("changeMaterial->,address:" + address + ",index:" + index + ",currentPages:" + currentPages);
                    // $("#viewcover").find("img").attr("src","//hkmaterials.etalk365.com/"+address+"/1.png");
                    if (address.lastIndexOf("/") === address.length - 1) {
                        address += "cfg.json";
                    } else {
                        address += "/cfg.json";
                    }
                    $.ajax({
                        type: 'get',
                        url: "/questionKnowledge/showTextbooksPages",
                        data: {'strUrl': address},
                        dataType: 'json',
                        async: false,
                        success: function (data) {
                            // console.log(JSON.stringify(data));
                            if (data.list != null && data.list !== "") {
                                // $("#viewcover").show();
                                var pages = data.list;
                                // console.log("pages:" + JSON.stringify(pages));
                                // if (pages.length == 0) {
                                //     changeMaterial(address, index, currentPages)
                                //     return;
                                // }
                                var pageObj = $('#page' + index);
                                pageObj.selectPageData(pages);

                                // 当前页码
                                pageObj.val(currentPages);
                                pageObj.selectPageRefresh();

                                console.log("currentTextbookIndex:" + currentTextbookIndex);
                                if (currentTextbookIndex === relateTextbookArray.length) {
                                    //关闭加载层
                                    layer.closeAll('loading');
                                }
                            }
                        }
                    });
                }
            }

            /*
             * 删除教材页码
             *
             */
            function deletetbitem(domthis) {
                if (domthis.parents('.textbookList').find('.textbookItem').length > 1) {
                    domthis.parent('.textbookItem').eq(0).remove();
                }
            }

            /*
             * 收缩展开教材页码
             *
             */
            function hidestate(domthis) {
                // console.log("hidestate:" + domthis.attr('hidestate'));
                if (domthis.attr('hidestate') === '0') {
                    domthis.attr('hidestate', '1');
                    domthis.text('展开');
                    $('#textbookList').hide('fast');
                } else {
                    domthis.attr('hidestate', '0');
                    domthis.text('收缩');
                    $('#textbookList').show('fast');
                }
            }

            function cancel() {
                window.event.preventDefault();
                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                parent.layer.close(index); //再执行关闭
                return false;
            }

            function save(isContinueAdd) {
                $("#submit-button").button('loading');

                var status = $('form').valid();
                if (!status) {
                    $("#submit-button").button('reset');
                    //没有通过验证
                    return false;
                }

                //单独校验关联教材和题目
                if ($("#relatedTextbooks1").val() == '') {
                    $("#relatedTextbooks1").parent().addClass("error");
                    $("#relatedTextbooks1").parent().addClass("error-border");
                    $("#relatedTextbooks1_text").focus();
                    $("#submit-button").button('reset');
                    return false;
                }

                if ($("#page1").val() == '') {
                    $("#page1").parent().addClass("error");
                    $("#page1_text").focus();
                    $("#submit-button").button('reset');
                    return false;
                }

                var textbookList = [];
                var items = $("#textbookList .textbookItem");
                $(items).each(function (i, v) {
                    var cIdx = parseInt(i) + 1;
                    var tb = $(v).find("input[name='relatedTextbooks" + cIdx + "']").val();
                    var pg = $(v).find("input[name='page" + cIdx + "']").val();
                    var pgName = $("#page" + cIdx).selectPageText();
                    var kp = $("#hidmistakeId" + cIdx).val();

                    console.log("kid:" + knowledgeId);
                    console.log("tb:" + tb);
                    console.log("pg:" + pg);
                    console.log("pgName:" + pgName);
                    console.log("kp:" + kp);

                    if (pg != null && pg != "") {
                        var pgArray = pg.split(",");
                        var pgNameArray = pgName.split(",");
                        for (var j = 0; j < pgArray.length; j++) {
                            var newObj = {
                                qknowledgeId: knowledgeId,
                                textbooksId: tb,
                                textbooksPage: pgArray[j],
                                textbooksPageName: pgNameArray[j],
                                knowledgePoint: kp
                            };
                            if (tb != "" && pgArray[j] != "" && pgNameArray[j] != "" && kp != "") {
                                textbookList.push(newObj);
                            }
                        }
                    }
                });

                // 检测教材知识点考点页码关联关系是否重复
                var uniqeTextbookList = uniqueKnow(textbookList);
                console.log("textbookList=>", textbookList);
                console.log("uniqeTextbookList=>", uniqeTextbookList);
                // 检测试卷中的题目是否重复
                if (uniqeTextbookList.length != textbookList.length) {
                    console.log("textbookList:", textbookList);
                    layer.msg("考点关联不能重复，请检查【教材、页码、考点】是否唯一", {icon: 2});
                    $("#submit-button").button('reset');
                    return;
                }

                var formData = {
                    id: knowledgeId,
                    cnName: $.trim($("#cnName").val()),
                    textbooksList: uniqeTextbookList,
                    isContinueAdd: isContinueAdd
                };
                console.log("edit knowledge,formData=>", formData);

                $.ajax({
                    type: "post",
                    url: "/questionKnowledge/submit",
                    data: JSON.stringify(formData),
                    dataType: "json",
                    contentType: "application/json",
                    success: function (res) {
                        $("#submit-button").button('reset');
                        //console.log(JSON.stringify(res));
                        if (res != null && res.status == 1) {
                            if (null != res.data && "" != res.data) {
                                knowledgeId = res.data.kid;
                            }

                            parent.layer.msg('操作成功', {icon: 1});
                            if (isContinueAdd == 0) {
                                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                parent.layer.close(index); //再执行关闭
                                if (isFromQuestion != 1) {
                                    parent.window.location.reload();
                                }
                            } else {
                                parent.window.location.reload();
                            }
                        } else {
                            parent.layer.msg('操作失败:' + res.msg, {icon: 2});
                        }
                    },
                    error: function () {
                        $("#submit-button").button('reset');
                        parent.layer.msg('系统异常:', {icon: 2});
                    }
                });
            }

            /**
             * 数组去重
             * @param array
             * @returns {*}
             */
            function unique(array) {
                var res = array.filter(function (item, index, array) {
                    return array.indexOf(item) === index;
                })
                return res;
            }

            function uniqueKnow(array) {
                // 对象去重方法
                var allArr = [];    //建立新的临时数组
                for (var i = 0; i < array.length; i++) {
                    var flag = true;
                    for (var j = 0; j < allArr.length; j++) {
                        // qknowledgeId
                        // textbooksId
                        // textbooksPage
                        // textbooksPageName
                        // knowledgePoint
                        if (array[i].qknowledgeId == allArr[j].qknowledgeId &&
                            array[i].textbooksId == allArr[j].textbooksId &&
                            array[i].textbooksPage == allArr[j].textbooksPage &&
                            array[i].knowledgePoint == allArr[j].knowledgePoint
                        ) {
                            flag = false;
                        }
                    }
                    if (flag) {
                        allArr.push(array[i]);
                    }
                }
                return allArr;
            }
        </script>
    </div>
</div>
</body>
</html>